package com.his.service.impl;

import com.his.entity.CaseHistory;
import com.his.entity.Patient;
import com.his.entity.Registration;
import com.his.entity.ResponseResult;
import com.his.mapper.PatientMapper;
import com.his.service.IPatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 病人基本信息表 服务实现类
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements IPatientService {

    @Resource
    public PatientMapper patientMapper;

    @Override
    public ResponseResult selectPatientByIdNo(Patient patient) {
        List<Patient>patients=patientMapper.selectPatientByIdNo(patient.getIdentificationno());
        if (Objects.isNull(patients)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("patient",patients);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectAllPatient() {
        List<Patient>patient1=patientMapper.selectAllPatient();
        if (Objects.isNull(patient1)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("patient",patient1);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult updateDiagnosisStatus(Registration registration) {
        Registration registrations=patientMapper.selectRegistrationById(registration.getId());
        if (Objects.isNull(registrations)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        registrations.setEndattendance(registration.getEndattendance());
        patientMapper.updateDiagnosisStatus(registrations);
        return new ResponseResult(200, "更新信息成功", null);
    }

    @Override
    public ResponseResult selectCaseHistoryByPatient(CaseHistory caseHistory) {
        List<CaseHistory>caseHistories=patientMapper.selectCaseHistoryByPatient(caseHistory.getRegistrationid());
        if (Objects.isNull(caseHistories)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("caseHistorie",caseHistories);
        return new ResponseResult(200, "查找信息成功", map);
    }
}
